
#ifndef _REQUEST_H_
#define _REQUEST_H_

#include <string.h> // size_t

//forward declaration
struct evhttp_request;
struct evbuffer;
struct evkeyvalq;

// wrapper around evhttp_request for our task
class Request {
public:
	Request(evhttp_request *req);
	~Request();

	const char *path() const;

	const char *getQuery() const;
	const char *postQuery() const;

	const char *getVar(const char *var) const;
	const char *postVar(const char *var) const;

	void addHeader(const char *name, const char *val);
	bool removeHeader(const char *name);

	void addResponse(const char *format, ...);
	void addBinaryResponse(const void *response, size_t size);
	void sendResponse();

	void sendError(int code);

private:
	evhttp_request *_request;
	evbuffer *response_buffer;
	evkeyvalq *get_headers;
	evkeyvalq *post_headers;
	evkeyvalq *input_headers;
	evkeyvalq *output_headers;
	const char *_path;
	char *get_query;
	char *post_query;

	void parseGetHeaders();
	void parsePostHeaders();
	bool parseQuery(const char *src, evkeyvalq *dest);
};

#endif
